﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PortalCurriculo.WebUI.UserControls.Basico
{
    public partial class TextBoxNumerico : UserControl
    {
        public int Value
        {
            get { return int.Parse(TextBox.Text); }
            set { TextBox.Text = value.ToString(); }
        }

        public string LabelText
        {
            get { return Label.Text; }
            set
            {
                Label.Visible = true;
                Label.Text = value;
            }
        }

        public bool Obrigatorio { private get; set; }
        public int MaxLength { private get; set; }
        public Unit Width { private get; set; }

        public bool Enabled
        {
            get { return TextBox.Enabled; }
            set { TextBox.Enabled = value; }
        }

        public string ValidationGroup
        {
            get { return TextBox.ValidationGroup; }
            set { TextBox.ValidationGroup = rfvTextBox.ValidationGroup = revTextBox.ValidationGroup = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            rfvTextBox.Visible = Obrigatorio;
            TextBox.MaxLength = MaxLength;
            if (Width != 0)
                TextBox.Width = Width;
        }

        protected override void Render(HtmlTextWriter writer)
        {
            Label.AssociatedControlID = TextBox.ID;
            base.Render(writer);
        }
    }
}